﻿using System;

public class Product
{
    private decimal price;

    public string Name { get; set; }
    public decimal Price 
    {
        get
        {
            return price;
        }
        set
        {
            if (value < 0)
            {
                throw new ArgumentOutOfRangeException("Price can not be negative");
            }
            decimal oldPrice = price;
            price = value;
            if (oldPrice < price)
            {
                OnPriceIncreased(oldPrice,value);
            }
        }
    }

    public event PriceIncreacementEventHandler PriceIncreased;

    public Product(string name, decimal price)
    {
        if (name == null)
        {
            throw new ArgumentNullException("Name can not be null.");
        }
        if (name == string.Empty)
        {
            throw new ArgumentOutOfRangeException("Name can not be empty.");
        }
        if (price < 0)
        {
            throw new ArgumentOutOfRangeException("Price can not be negative.");
        }

        this.Name = name;
        this.price = price;
    }

    public void OnPriceIncreased(decimal oldPrice, decimal newPrice)
    {
        if (PriceIncreased != null)
        {
            PriceIncreasementEventArgs arguments = new PriceIncreasementEventArgs(oldPrice, newPrice);
            PriceIncreased(this, arguments);
        }
    }

}
